package com.sh.data.engine.application.model.dto.normalization.standard;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.math.BigDecimal;

/**
 * @Version 1.0 @Author:xinyan @Date:2022/7/21 @Content:
 */
@Data
@AllArgsConstructor
public class DictionaryTendResposne {

    private Integer hitCount;

    private Integer fieldCount;

    private String percentStr;

    @Schema(description = "时间")
    private String date;

    public void initPercentStr() {
        int hit = hitCount == null ? 0 : hitCount;
        int count = fieldCount == null ? 0 : fieldCount;
        if (count == 0) {
            percentStr = "0%";
        } else {
            double doubleValue =
                new BigDecimal(hit * 100.0 / count).setScale(2, BigDecimal.ROUND_HALF_DOWN).doubleValue();
            String temp = doubleValue + "";
            temp = temp.replaceAll("0+?$", "");
            temp = temp.replaceAll("[.]$", "");
            temp = doubleValue + "%";
            percentStr = temp;
        }
    }
}
